window.onload=function () {
    var userId = sessionStorage.getItem('userId');
    console.log(userId);
    var provider=[];
    var machines_name=[];
    var manage_name=[];
    var IP='39.107.58.193:8080';
    //默认的请求
    var modelSend = {
        "model": 'new_machines_abnoral_board',
        "condition": {},
        "item": {"sale_amount": [1,2],
            "main_index": {"sale_amount": 1}//主指标
        }//数据指标
    };
    $(".header a[href='#pageone']").click(function(){
        modelSend.model="new_machines_abnoral_board";
        modelSend.condition.provider = [];
        modelSend.condition.machines_name = [];
        modelSend.condition.manage_name=[];
        console.log(modelSend)
    });
    console.log(modelSend)
    $.ajax({
        url: "http://"+IP+"/data-center/recentBorad/getRecentBoardInfo?token="+userId,
        type: "POST",
        data:{"paramData":JSON.stringify(modelSend)},
        success: function(data) {
            console.log(data)
            var manageData=data.manageData;
            var str='';
            for (var i=0;i<manageData.length;i++) {
                str += '<li ><a id='+manageData[i].id+' href="#pageName" class="ui-btn ui-btn-icon-right ui-icon-carat-r">' + manageData[i].label + '</a></li>';
            }
            $(".list").html(str)
        }
    });
    $('.list').on('click','li>a',function(){
        manage_name.length=0;
        modelSend.condition.manage_name = [];
        manage_name.push($(this).attr('id'));
        modelSend.condition.manage_name = manage_name;
        name();
    });
    function  name() {
        console.log(modelSend)
        $.ajax({
            url: 'http://' + IP + '/data-center/recentBorad/getRecentBoardInfo?token=' +userId,
            type: "POST",
            data: {"paramData": JSON.stringify(modelSend)},
            success: function (data) {
                console.log(data)
                var providerData=data.providerData;
                var str='';
                for (var i=0;i<providerData.length;i++) {
                    str += '<li ><a id='+providerData[i].id+' href="#pageBoard" class="ui-btn ui-btn-icon-right ui-icon-carat-r">' + providerData[i].label + '</a></li>';
                }
                $(".name").html(str)
            }
        });
        $('.name').on('click','li>a',function(){
            provider.length=0;
            modelSend.condition.provider=[];
            provider.push( $(this).attr('id'));
            modelSend.condition.provider = provider;
            modelSend.condition.manage_name = manage_name;
            console.log(modelSend);
            board();
        });
    };
    function board() {
        $.ajax({
            url: 'http://' + IP + '/data-center/recentBorad/getRecentBoardInfo?token=' +userId,
            type: "POST",
            data: {"paramData": JSON.stringify(modelSend)},
            success: function (data) {
                console.log(data)
                var pointsData=data.pointsData;
                var str='';
                for (var i=0;i<pointsData.length;i++) {
                    str += '<li ><a id='+pointsData[i].id+' href="#pagedetail" class="ui-btn ui-btn-icon-right ui-icon-carat-r">' + pointsData[i].label + '</a></li>';
                }
                $(".board").html(str)
            }
        });
        $('.board').on('click','li>a',function(){
            machines_name.length=0;
            modelSend.condition.machines_name=[];
            machines_name.push($(this).attr('id'));
            modelSend.condition.provider = provider;
            modelSend.condition.machines_name = machines_name;
            modelSend.condition.manage_name=manage_name;
            detail();
        });
    };
    function detail(){
        var model = {
            "model": 'new_machines_abnoral_board',
            "condition": {},
            "item": {"sale_amount": [1,2],
                "main_index": {"sale_amount": 1}//主指标
            }//数据指标
        };
        model.model="new_machines_abnoral_detail_board";
        model.condition.provider = provider;
        model.condition.machines_name = machines_name;
        model.condition.manage_name=manage_name;
        console.log(model);
        $.ajax({
            url: 'http://' + IP + '/data-center/recentBorad/getRecentBoardInfo?token=' + userId,
            type: "POST",
            data: {"paramData": JSON.stringify(model)},
            success: function (data) {
                console.log(data)
                var str='';
                for (var i=0;i<data.data.length;i++){
                    str+='<tr>' +
                        '<th>'+data.data[i].machinesCode+'</th>' +
                        '<th>'+data.data[i].machinesName+'</th>' +
                        '<th>'+data.data[i].lastTradeDate+'</th>' +
                        '<th>'+data.data[i].spaceTime+'</th>' +
                        '</tr>'
                }
                $("#myTab tbody").html(str)
            }
        })
    };


}
